<?php

namespace App\Http\Requests;

use App\Http\Constants\CodingStatusConstants;
use App\Models\CoinsType;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Validation\Rule;

class CoinsCodingJuniorCreateRequest extends FormRequest
{
    use CommonRequest;

    /**
     * Determine if the user is authorized to make this request.
     *
     * @return bool
     */
    public function authorize()
    {
        return true;
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        $rules = [
            'subsidy' => [
                'required',
                Rule::in(array_column(CodingStatusConstants::IS_SUBSIDY, 'value'))
            ],
            'type' => [
                'required',
                Rule::in(array_column(CodingStatusConstants::JUNIOR_TYPE, 'value'))
            ],
            'type_name' => [
                'required',
                Rule::unique((new CoinsType())->getTable(), 'type_name')
            ],
        ];

        $rules = array_merge($rules, CoinsCodingRequest::baseRules());
        return $rules;
    }

    public function messages()
    {
        $messages = [
            'subsidy.required' => '是否为补贴红包必选',
            'subsidy.in' => '红包类型值只能为0或者1',
            'type.required' => '编码类型必选',
            'type.in' => '编码类型值只能为0或者1',
            'type_name.required' => '编码描述必填',
            'type_name.unique' => '编码描述已存在',
        ];
        $messages = array_merge($messages, CoinsCodingRequest::baseMessage());
        return $messages;
    }
}
